public class IsSymmetrical {
    // 对称的二叉树
    // https://www.nowcoder.com/practice/ff05d44dfdb04e1d83bdbdab320efbcb?tpId=295&tags=&title=&difficulty=0&judgeStatus=0&rp=0&sourceUrl=%2Fexam%2Foj%3Fpage%3D1%26tab%3DSQL%25E7%25AF%2587%26topicId%3D295
    public boolean isSymmetrical (TreeNode pRoot) {
        // write code here
        if (pRoot == null) {
            return true;
        }
        return isSymmetricalChild(pRoot.left, pRoot.right);
    }

    private boolean isSymmetricalChild(TreeNode leftTree, TreeNode rightTree) {
        if (leftTree == null && rightTree == null) {
            return true;
        } else if ((leftTree == null && rightTree != null)
                || (leftTree != null && rightTree == null)) {
            return false;
        }
        if (leftTree.val != rightTree.val) {
            return false;
        }
        boolean leftResult = isSymmetricalChild(leftTree.left, rightTree.right);
        if (!leftResult) {
            return false;
        }
        return isSymmetricalChild(leftTree.right, rightTree.left);
    }
}
